'''
概念：
    元素定位/对象识别
八大定位方式：
    id
    name
    class
    tag
    xpath
    css
    link
    partial_link
'''

from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
from options import options

url = r'https://www.bilibili.com/'
driver = webdriver.Chrome(options=options)
driver.get(url)
driver.maximize_window()
# 1、id定位：首选
# driver.find_element(By.ID, 'kw').send_keys('selenium')
# driver.find_element(By.ID, 'su').click()
# sleep(3)
#
# # 2、name定位：次选
# driver.find_element(By.NAME, 'wd').send_keys('selenium2')
# driver.find_element(By.ID, 'su').click()
# sleep(3)
#
# # 3、tag定位：了解
# driver.find_elements(By.TAG_NAME, 'input')[7].send_keys('selenium3')
# driver.find_elements(By.TAG_NAME, 'input')[8].click()
# sleep(3)
#
# # 4、class定位：适合定位 class 为单属性的元素
# driver.find_element(By.CLASS_NAME, 's_ipt').send_keys('s4')
# # driver.find_element(By.CLASS_NAME,'self-btn').click()
# driver.find_elements(By.CLASS_NAME, 'bg')[2].click()
# sleep(4)
# driver.quit()
#5.xpath定位
'''
/根路径
//相对路径
* 所有标签
input 指定标签
[@id-"kw] 指定属性

'''
# driver.find_element(By.XPATH,'//form[@id="form"]/span/input[@id="kw"]').send_keys('python')
# sleep(3)
# driver.find_element(By.XPATH,'//form[@id="form"]/span/input[@id="su"]').click()
# sleep(6)
# driver.quit()

#6.CSS定位 id选择器 class选择器

'''
#  id
.  class
'''

# driver.find_element(By.CSS_SELECTOR, '#kw').send_keys('s10')
# driver.find_element(By.CSS_SELECTOR, '#su').click()
# sleep(3)
#driver.find_element(By.CSS_SELECTOR, '.s_ipt').send_keys('s11')
# driver.find_element(By.CSS_SELECTOR, '.bg .s_btn').click()  # 特别注意
# sleep(3)

#其他属性
# driver.find_element(By.CSS_SELECTOR, '[name="wd"]').send_keys('s12')
# driver.find_element(By.CSS_SELECTOR, '.bg .s_btn').click()
# sleep(3)
# driver.find_element(By.CSS_SELECTOR,'[class="nav-search-input"]').send_keys('名侦探柯南')
# driver.find_element(By.CSS_SELECTOR,'.nav-search-btn').click()

# # css定位 之 使用多个属性
# driver.find_element(By.CSS_SELECTOR, '.nav-search-input[type="text"]').send_keys('国创')
# driver.find_element(By.CSS_SELECTOR, '.nav-search-btn').click()
# sleep(3)
# # css定位 之 使用层级
# driver.find_element(By.CSS_SELECTOR, 'form[id="nav-searchform"]>div>input[class="nav-search-input"]').send_keys('名侦探柯南')
# driver.find_element(By.CSS_SELECTOR, '.nav-search-btn').click()
# driver.find_element(By.CSS_SELECTOR, '.bg .s_btn[type="submit"][value="百度一下"]').click()
# sleep(3)

# # 7、link定位
# driver.find_element(By.LINK_TEXT,'新闻').click()
# sleep(3)
# driver.find_element(By.LINK_TEXT,'赛事').click()

# 8、partial_link定位
# driver.find_element(By.PARTIAL_LINK_TEXT, '国').click()
sleep(10)
driver.quit()
